package com.tanhua.controller;

import com.tanhua.exception.BusinessException;
import com.tanhua.mondb.Movement;
import com.tanhua.server.MovementsService;
import com.tanhua.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/movements")
public class MovementController {
    @Autowired
    private MovementsService movementsService;
    /*发布动态
    * */
    @PostMapping
    public ResponseEntity movements(Movement movement,
                                    MultipartFile imageContent[]) throws IOException, BusinessException {

        movementsService.publishMovements(movement,imageContent);
       return ResponseEntity.ok(null);
    }
    /*查看个人动态
    * */
    @GetMapping("/all")
    public ResponseEntity movementsByUserId(Long userId,
                                            @RequestParam(defaultValue="1") Integer page,
                                            @RequestParam(defaultValue="10") Integer pageSize){
       PageResult ps =  movementsService.movementsByUserId(userId,page ,pageSize);
        return  ResponseEntity.ok(ps);

        }
}
